package com.cx.algrithm.leetcode.day1;

/**
 * @Author: robert.song
 * @Date: Created in 2021/12/22
 */

import java.util.LinkedList;

/**
 * 用两个栈实现一个队列，队列的声明如下，请实现它的两个函数appendTail和deleteHead,分别完成在队列尾插入整数和在队列头删除整数的功能
 */
public class Queue {

    static LinkedList<Integer> A = new LinkedList<>(), B = new LinkedList<>();

    public static void main(String[] args) {
        for (int i = 0; i < 10; ) {
            appendTail(i++);
        }
        System.out.println(A);
        System.out.println(deleteHead());
        ;
        System.out.println(A);
        System.out.println(B);
    }

    public static void appendTail(int value) {
        A.addLast(value);
    }

    public static int deleteHead() {
        if (!B.isEmpty()) {
            return B.removeLast();
        }
        if (A.isEmpty()) {
            return -1;
        }
        while (!A.isEmpty()) {
            B.addLast(A.removeLast());
        }
        return B.removeLast();
    }
}
